package com.blockchain.console.servlets.financial.bzc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blockchain.common.enums.XlbZcStatus;
import com.blockchain.console.service.financial.BManage;
import com.blockchain.console.service.financial.entity.BEntity;
import com.blockchain.console.servlets.financial.AbstractFinancialServlet;
import com.blockchain.framework.http.servlet.annotation.Right;
import com.blockchain.framework.resource.PromptLevel;
import com.blockchain.framework.service.ServiceSession;
import com.blockchain.util.parser.EnumParser;
import com.blockchain.util.parser.IntegerParser;

@Right(id = "C_FINANCIAL_XLBZC", name = "虚拟币转出-审核")
public class ZbSh extends AbstractFinancialServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void processGet(HttpServletRequest request, HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		BManage manage = serviceSession.getService(BManage.class);
		int id = IntegerParser.parse(request.getParameter("id"));
		BEntity t = manage.getBzc(id);
		request.setAttribute("result", t);
		forwardView(request, response, getClass());
	}

	@Override
	protected void processPost(final HttpServletRequest request, HttpServletResponse response,
			ServiceSession serviceSession) throws Throwable {
		try {
			BManage manage = serviceSession.getService(BManage.class);
			XlbZcStatus status = EnumParser.parse(XlbZcStatus.class, request.getParameter("zczt"));
			int id = IntegerParser.parse(request.getParameter("id"));
			String bz = request.getParameter("bz");
			manage.updateBzc(id, status, bz);
			sendRedirect(request, response, getController().getURI(request, BzcList.class) + "?zczt=" + status.name());
		} catch (Throwable e) {
			prompt(request, response, PromptLevel.ERROR, e.getMessage());
			processGet(request, response, serviceSession);
		}
	}

}
